<?php

class Core_Helper_Article_Helper {

    public function getTemplateByCategoryId($categoryId){
        $idPath = Kd_Data_Factory::getQueryDcl()
                        ->from('{t}article_category')
                        ->select()->field('id_path')->closest()
                        ->where()->eq('id', ':id:i')->closest()
                        ->addParameter('id', $categoryId)->fetch()->getFirstValue();
        $idPath = substr($idPath,0,-1);
        $ids = explode('_', $idPath);
        $template = Kd_Data_Factory::getQueryDcl()
                        ->from('{t}article_category', 'b')
                        ->innerJoin('{t}website_template', 'c', 'b.template_id', 'c.id')
                        ->field('c.*')
                        ->contain('b.id', ':id:i')->neq('b.template_id',':template_id:i')
                        ->addParameter(array('id'=>$ids,'template_id'=>0))->desc('level')
                        ->limit(1)->fetch()->getFirstRow();
        return $template;
    }

    public function getCategorys(){
        $categorys = App::getModel('article/collection_category')->load();
        return $categorys;
    }

    public function getContents(){
        $contents = App::getModel('article/collection_content');
        return $contents;
    }
}